package String;

/**
 * @author 孤雪唯方
 * @date 2025/05/17
 * @description String.compareTo()方法验证
 */
public class CompareTo {
    public static void main(String[] args) {
        String str1 = "abc";
        String str2 = "abd";
        String str3 = "aba";
        String str4 = "abc";
        // 按照字母顺序(字典序)比较两个字符串
        System.out.println(str1.compareTo(str2));// 输出-1
        System.out.println(str1.compareTo(str3));// 输出2
        System.out.println(str1.compareTo(str4));// 输出0

        // 按照字母顺序(字典序)比较两个字符串，忽略大小写
        String str5 = "abc";
        String str6 = "Abd";
        String str7 = "aBA";
        String str8 = "aBC";
        System.out.println(str5.compareToIgnoreCase(str6));// 输出-1
        System.out.println(str5.compareToIgnoreCase(str7));// 输出2
        System.out.println(str5.compareToIgnoreCase(str8));// 输出0
    }
}
